package com.zwh.se.oop;

class Person1{
    public void run(){}
}
class Student1 extends Person1{
}
class Teacher1 extends Person1{
}

/**
 * instanceof :该代码能否编译通过,主要是看声明变量x的类型和Y是否存在子父类的关系.有"子父类关"系就编译通过,没有子父类关系就是编译报错.
 *
 */
public class instanceofDemo {
    public static void main(String[] args) {
        Object o = new Student1();
        System.out.println(o instanceof Student1);//true
        System.out.println(o instanceof Person1);//true
        System.out.println(o instanceof Object);//true
        System.out.println(o instanceof Teacher1);//false
        System.out.println(o instanceof String);//false
        System.out.println("--------------------------------------------------");
                Person1 p = new Student1();
        System.out.println(p instanceof Student1);//true
        System.out.println(p instanceof Person1);//true
        System.out.println(p instanceof Object);//true
        System.out.println(p instanceof Teacher1);//false
//        System.out.println(p instanceof String); //编译报错
        System.out.println("--------------------------------------------------");
                Student1 s = new Student1();
        System.out.println(s instanceof Student1);//true
        System.out.println(s instanceof Person1);//true
        System.out.println(s instanceof Object);//true
//        System.out.println(s instanceof Teacher1);//编译报错
//        System.out.println(s instanceof String);//编译报错

    }
}
